package com.sinosun.autotestmachine.tools.proxy.callback.buddy;

import android.util.Log;

public class BuddyActionInformation implements java.lang.Comparable<BuddyActionInformation>{
	private BudduyActionType type;
	private BuddyMsg info;
	
	public String toString() {
		String ret = type + " info arg1=" + info.arg1 + ",arg2=" + info.arg2 + ",arg3=" + info.arg3 + ",arg4=" + info.arg4;
		return ret;
	}
	
	public BuddyActionInformation() {
		type = null;
		info = null;
	}
	
	public BudduyActionType getBudduyActionType() {
		return this.type;
	}
	
	public void setBudduyActionType(BudduyActionType type) {
		this.type = type;
	}
	
	public BuddyMsg getBuddyMsg() {
		return this.info;
	}
	
	public void setBuddyMsg(BuddyMsg info) {
		this.info = info;
	}
	
	@Override public int compareTo(BuddyActionInformation other) {
		Log.e("XXX", "super compareTo()()");
		switch (this.getBudduyActionType()) {
		case AddBuddy:
			if (this.getBudduyActionType() == BudduyActionType.AddBuddy
				&& this.getBudduyActionType() == other.getBudduyActionType() 
				&& other.getBuddyMsg().getArg(1).equals(this.getBuddyMsg().getArg(1))
				&& other.getBuddyMsg().getArg(2).equals(this.getBuddyMsg().getArg(2))
				&& other.getBuddyMsg().getArg(3).equals(this.getBuddyMsg().getArg(3))	
//				&& other.getBuddyMsg().getArg(4).equals(this.getBuddyMsg().getArg(4))
					) {
				return 0;
				}
			break;
		case AddedPolicyChanged:
			if (this.getBudduyActionType() == BudduyActionType.AddedPolicyChanged
					&& this.getBudduyActionType() == other.getBudduyActionType() 
					&& other.getBuddyMsg().getArg(1).equals(this.getBuddyMsg().getArg(1))
					&& other.getBuddyMsg().getArg(2).equals(this.getBuddyMsg().getArg(2))
					&& other.getBuddyMsg().getAddPolicy() == this.getBuddyMsg().getAddPolicy()
					) {
					return 0;
				}
			break;
		case AgreeAddBuddy:
			Log.e("XXX", "this " + this.toString());
			Log.e("XXX", "other " + other.toString());
			if (this.getBudduyActionType() == BudduyActionType.AgreeAddBuddy
					&& this.getBudduyActionType() == other.getBudduyActionType() 
					&& other.getBuddyMsg().getArg(1).equals(this.getBuddyMsg().getArg(1))
					&& other.getBuddyMsg().getArg(2).equals(this.getBuddyMsg().getArg(2))
					&& other.getBuddyMsg().getArg(3).equals(this.getBuddyMsg().getArg(3))
				) {
				return 0;
				}
			break;
		case BuddyInfoChanged:
			if (this.getBudduyActionType() == BudduyActionType.BuddyInfoChanged
					&& this.getBudduyActionType() == other.getBudduyActionType() 
					&& other.getBuddyMsg().getArg(1).equals(this.getBuddyMsg().getArg(1))
					&& other.getBuddyMsg().getArg(2).equals(this.getBuddyMsg().getArg(2))
					&& other.getBuddyMsg().getArg(3).equals(this.getBuddyMsg().getArg(3))
					) {
				return 0;
				}
			break;
		case RefuseAddBuddy:
			Log.e("XXX", "this -> " + this.toString());
			Log.e("XXX", "other -> " + other.toString());
			if (this.getBudduyActionType() == BudduyActionType.RefuseAddBuddy
					&& this.getBudduyActionType() == other.getBudduyActionType() 
					&& other.getBuddyMsg().getArg(1).equals(this.getBuddyMsg().getArg(1))
					&& other.getBuddyMsg().getArg(2).equals(this.getBuddyMsg().getArg(2))
					&& other.getBuddyMsg().getArg(3).equals(this.getBuddyMsg().getArg(3))
					) {
				return 0;
				}
			break;
		case RemoveBuddy:
			if (this.getBudduyActionType() == BudduyActionType.RemoveBuddy
					&& this.getBudduyActionType() == other.getBudduyActionType() 
					&& other.getBuddyMsg().getArg(1).equals(this.getBuddyMsg().getArg(1))
					) {
				return 0;
				}
			break;
		}
		return -1;
	}
}
